<template>
	<uni-popup ref="popup" type="center" @maskClick="no" :is-mask-click="false" :mask-click="false">
		<view class="renew">
			<view class="ground">
				<image :src="require(`../../../static/img/renew/${auth}.png`)" mode=""
					style="width: 540rpx;height:684rpx"></image>
				<view class="content">
					<view class="title">{{`允许访问你的“`+dict[auth]+`”权限`}}</view>
					<view class="desc">{{obj[auth]}}</view>
					<view class="btn1" @click="handleOpen">马上开启</view>
					<view class="btn2" @click="cancel">以后再说</view>
				</view>

			</view>
			<!-- 	<view v-if="auth=='location'" class="icon-a-qingkongpng iconfont" style="color:#3C8EFF;font-size: 100rpx;" 
				@click="cancel"> </view> -->
		</view>
		<!-- </view> -->
	</uni-popup>
</template>

<script>
	import uniPopup from '@/components/uni-ui/uni-popup/uni-popup.vue'
	import permision from "@/common/js/permission.js"
	import {
		watchPositon,
		openMyGps,
		getLocation,
		requestAndroid
	} from "@/common/js/location.js"
	const dict = {
		'location': '位置',
		'call': '电话',
		'luyin': '录音',
	}
	export default {
		components: {
			uniPopup,
		},
		computed: {

		},
		mounted() {},
		props: {
			// renewData: {
			// 	type: Object,
			// 	default: {}
			// },
			bol: {
				type: Boolean,
				default: true
			},
			auth: {
				type: String,
				default: 'location'
			},
		},
		data() {
			return {
				dict,
				// auth: 'luyin',
				call: require("../../../static/img/renew/call.png"),
				luyin: require("../../../static/img/renew/luyin.png"),
				type: 1, //0强制更新 1不强制
				obj: {
					'call': '为了避免影响您正常接单流程，请开启电话权限',
					'luyin': '您还没有开启录音权限，开启后，将录音记录服务全过程！',
					'location': '您还没有开启位置权限，开启后，即可查看附近可接订单！',
				}
			}
		},
		methods: {
			no() {
				return
			},
		async handleOpen() {
				// 安卓电话授权
				this.cancel()
				if (this.auth == 'call') {
					permision.gotoAppPermissionSetting()
					return
					// requestAndroid('android.permission.CALL_PHONE','通话权限')
					// return
				} else if (this.auth == 'luyin') {
					let isIos = plus.os.name == "iOS"
					if(isIos){
						
						var avaudiosession = plus.ios.import("AVAudioSession");
						
						var avaudio = avaudiosession.sharedInstance();
						avaudio.requestRecordPermission(()=>{  
						    console.log('回调完成');  
						});  
						var permissionStatus = avaudio.recordPermission();  
						console.log("permissionStatus:" + permissionStatus)
						if([1970168948,1684369017].indexOf(permissionStatus)>-1){
							permision.gotoAppPermissionSetting()
						}
					}
					else {
						permision.gotoAppPermissionSetting()
					}
					
					return
					// 录音 // ios
					// let isIos = plus.os.name == "iOS"
					// let result = 0
					// if(isIos){
					// 	result = await permision.judgeIosPermission('record')
					// 	if(result!=1){
					// 		permision.gotoAppPermissionSetting()
					// 	}
					// } else {
					// 	result= await requestAndroid('android.permission.RECORD_AUDIO','录音权限')
					// }
					
					// if (isIos) {
					// 	let UIApplication = plus.ios.import("UIApplication");
					// 	let application2 = UIApplication.sharedApplication();
					// 	let NSURL2 = plus.ios.import("NSURL");
					// 	// let setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");		
					// 	let setting2 = NSURL2.URLWithString("app-settings:");
					// 	application2.openURL(setting2);

					// 	plus.ios.deleteObject(setting2);
					// 	plus.ios.deleteObject(NSURL2);
					// 	plus.ios.deleteObject(application2);
					// } else {
					// 	// console.log(plus.device.vendor);
					// 	let Intent = plus.android.importClass("android.content.Intent");
					// 	let Settings = plus.android.importClass("android.provider.Settings");
					// 	let Uri = plus.android.importClass("android.net.Uri");
					// 	let mainActivity = plus.android.runtimeMainActivity();
					// 	let intent = new Intent();
					// 	intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
					// 	let uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
					// 	intent.setData(uri);
					// 	mainActivity.startActivity(intent);
					// }
				} else if (this.auth == 'location') {
					// 获取定位
					await getLocation()
					// plus.nativeUI.toast('获取定位成功！')

				}
			},
			initAuth() {
				let UIApplication = plus.ios.importClass('UIApplication');
				let application2 = UIApplication.sharedApplication();
				let NSURL2 = plus.ios.importClass('NSURL');
				let setting2 = NSURL2.URLWithString('app-settings:'); // 打开应用权限
				application2.openURL(setting2);
				plus.ios.deleteObject(setting2);
				plus.ios.deleteObject(NSURL2);
				plus.ios.deleteObject(application2);
			},
			cancel() {
				this.$refs.popup.close()
				this.$emit('handleFlag', false)
			},

		},
		watch: {
			// 监听输入框值的变化-对应的触底的页码更新
			bol(newValue, oldValue) {
				console.log(newValue, oldValue, '输入框的值是');
				if (newValue !== oldValue) {
					if (newValue) {
						this.$refs.popup.open()
					} else {
						this.$refs.popup.close()
					}
				}
			},
		}

	}
</script>

<style lang="scss" scoped>
	.center{
		background: none!important;
	}
	.a {
		width: 100vw;
		height: 100vh;
		box-sizing: border-box;
		background: rgba(0, 0, 0, 0.5);
		padding-top: 300rpx
	}

	.ground {
		height: 700rpx;
		position: relative;
	}

	.renew {
		// background:#999999;
		height: 400rpx;
		width: 500rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;

		image {
			display: block;

		}
	}

	.content {
		position: absolute;
		top: 270rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 20rpx 60rpx;

		// left: 224rpx;
		.title {
			font-size: 36rpx;
			font-weight: 500;
			color: #333333;
			margin-bottom: 8px;
		}

		.desc {
			text-align: center;
			font-size: 28rpx;
			color: #666666;
		}
	}

	.btn1 {
		width: 322rpx;
		height: 74rpx;
		margin: 36rpx 0 16px;
		line-height: 74rpx;
		text-align: center;
		// position: absolute;
		background-color: rgba(60, 142, 255, 1);
		color: #FFF;
		// bottom:118rpx;
		// left: 124rpx;
		font-size: 32rpx;
		border-radius: 56rpx;
	}

	.btn2 {
		// position: absolute;
		color: rgba(153, 153, 153, 1);
		// bottom:60rpx;
		// left: 224rpx;
	}
</style>
